home *** CD-ROM | disk | FTP | other *** search
- Path: news.bellglobal.com!stupy
- From: stupy@freenet.durham.org (Steve Tupy)
- Newsgroups: comp.lang.c
- Subject: Re: Recursive function -> how do you exit one?
- Date: 30 Jan 1996 20:43:21 GMT
- Organization: Durham Free-Net
- Message-ID: <4elvt9$ood@news.bellglobal.com>
- References: <4eh1g8$aba@pulp.ucs.ualberta.ca> <310d27a6.171790522@news.demon.co.uk>
- NNTP-Posting-Host: 204.101.165.17
- X-Newsreader: TIN [version 1.2 PL2]
-
- : You need to return a value which makes all the recursed functions exit
- : without further processing.
-
- : if the function returns an int then you could return -1 as aborted.
- : if it returns a char or char* you can use a (first) character that
- : cannot exist in your string. eg 0xff
-
- : char* foo()
- : {
- : result=foo();
- : if(*result!=0xff)
- : {
- : // process things here //
- : if (aborted) return "\xff";
- : }
- : return result;
- : }
-
- : Does that help?
-
- What is result, an int? Where is it defined? Don't you agree that it
- should also be static? If not, you might find that its value gets lost on
- the stack, especially when you are unwinding the stack during a recursive
- call...
-
- Just asking ;)
-
- Take care
-
- --
- Steve
-